package com.example.activity;

import java.util.ArrayList;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import com.example.fragment.IMainActivity;
import com.example.tools.Constants;
import com.example.tools.SlideShowView;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.benchi.ncar.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ImageView;

public class SplashActivity extends Activity {

	@ViewInject(R.id.show_view)
	private SlideShowView mSlideShowView;
	private ArrayList<String> mUrlStr;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.slide_view);
		ViewUtils.inject(this);
		mSlideShowView.setIsOpenReset(true);
		mSlideShowView.setAutoPlay(false);
		mSlideShowView.setIsDisplaySign(true);
		mSlideShowView.setHandler(handler);
		mUrlStr = new ArrayList<String>();
		new Thread(runnable).start();
	}

	private Handler handler = new Handler() {
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 1:
				if (mUrlStr.size()>0) {
					mSlideShowView.setImgStringPhoto(mUrlStr);	
				}else {
					ArrayList<Integer> img=new ArrayList<Integer>();
					img.add(R.drawable.defult_login);
					mSlideShowView.setImgIntPhoto(img);
				}
				
				mSlideShowView.initData();
				break;
			case 3:
				Intent intent = new Intent(SplashActivity.this,
						IMainActivity.class);
				startActivity(intent);
				finish();
				break;
			}
		};
	};
	Runnable runnable = new Runnable() {
		@Override
		public void run() {
			long start = System.currentTimeMillis();
			try {
//				Document doc = Jsoup.connect(Constants.STATE_ANIMATION).timeout(2000).get();
//				Elements li = doc.select("li");
//				for (Element element : li) {
//					String str = element.attr("data-background");
//					mUrlStr.add(str);
//				}
				handler.sendEmptyMessage(1);
			} catch (Exception e) {
				 System.out.println("Time is:"+(System.currentTimeMillis()-start) + "ms");
				handler.sendEmptyMessage(1);
			}
		}
	};
}
